package jp.anago_dev.takarush_helper.map;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class CurrentLocationOverlay extends Overlay {

    private double mLatitude;

    private double mLongitude;

    private final int mRadius = -20;

    public void setCurrentLocation(double latitude, double longitude) {
        mLatitude = latitude;
        mLongitude = longitude;
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {

        if (shadow == false) {
            Projection projection = mapView.getProjection();

            Double lat = mLatitude * 1E6;
            Double lon = mLongitude * 1E6;

            // GeoPointを作成
            GeoPoint geoPoint = new GeoPoint(lat.intValue(), lon.intValue());

            // 画面の解像度にあわせて描画位置を変換する
            Point point = new Point();
            projection.toPixels(geoPoint, point);

            // 描画範囲設定
            RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);

            // 背景を設定
            RectF backRect = new RectF(point.x + 2 + mRadius, point.y - 3 * mRadius, point.x + 65, point.y + mRadius);

            // 描画設定
            Paint paint = new Paint();
            paint.setARGB(255, 0, 0, 180);
            paint.setTextSize(30.0f);
            paint.setAntiAlias(true);
            paint.setFakeBoldText(true);

            Paint backPaint = new Paint();
            backPaint.setARGB(230, 50, 50, 50);
            backPaint.setAntiAlias(true);

            // 現在地を描画
            canvas.drawOval(oval, paint);
            canvas.drawRoundRect(backRect, 5, 5, backPaint);
//            canvas.drawText("現在地", point.x + 2 * mRadius, point.y, paint);
        }

        super.draw(canvas, mapView, shadow);

    }

    @Override
    public boolean onTap(GeoPoint p, MapView mapView) {
        return false;
    }

}
